package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TItems;
import com.ruoyi.system.service.ITItemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品信息Controller
 * 
 * @author 张倍
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/items")
public class TItemsController extends BaseController
{
    @Autowired
    private ITItemsService tItemsService;

    /**
     * 查询商品信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:items:list')")
    @GetMapping("/list")
    public TableDataInfo list(TItems tItems)
    {
        startPage();
        List<TItems> list = tItemsService.selectTItemsList(tItems);
        return getDataTable(list);
    }

    /**
     * 导出商品信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:items:export')")
    @Log(title = "商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TItems tItems)
    {
        List<TItems> list = tItemsService.selectTItemsList(tItems);
        ExcelUtil<TItems> util = new ExcelUtil<TItems>(TItems.class);
        util.exportExcel(response, list, "商品信息数据");
    }

    /**
     * 获取商品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:items:query')")
    @GetMapping(value = "/{item1Id}")
    public AjaxResult getInfo(@PathVariable("item1Id") Integer item1Id)
    {
        return success(tItemsService.selectTItemsByItem1Id(item1Id));
    }

    /**
     * 新增商品信息
     */
    @PreAuthorize("@ss.hasPermi('system:items:add')")
    @Log(title = "商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TItems tItems)
    {
        return toAjax(tItemsService.insertTItems(tItems));
    }

    /**
     * 修改商品信息
     */
    @PreAuthorize("@ss.hasPermi('system:items:edit')")
    @Log(title = "商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TItems tItems)
    {
        return toAjax(tItemsService.updateTItems(tItems));
    }

    /**
     * 删除商品信息
     */
    @PreAuthorize("@ss.hasPermi('system:items:remove')")
    @Log(title = "商品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{item1Ids}")
    public AjaxResult remove(@PathVariable Integer[] item1Ids)
    {
        return toAjax(tItemsService.deleteTItemsByItem1Ids(item1Ids));
    }
}
